<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Transdmin Light</title>

<!-- CSS -->
<link href="<spring:url value="/admin/style/css/transdmin.css"/>" rel="stylesheet" type="text/css" media="screen" />
<!--[if IE 6]><link rel="stylesheet" type="text/css" media="screen" href="<spring:url value="/admin/style/css/ie6.css"/>" /><![endif]-->
<!--[if IE 7]><link rel="stylesheet" type="text/css" media="screen" href="<spring:url value="/admin/style/css/ie7.css"/>" /><![endif]-->

<!-- JavaScripts-->
<script type="text/javascript" src="<spring:url value="/admin/style/js/jquery.js"/>"></script>
<script type="text/javascript" src="<spring:url value="/admin/style/js/jNice.js"/>"></script>
<script>
$(function() {
	$("#linkForm").submit(function(){
		var title = $("#title").attr('value');
		var url = $("#url").attr('value');
		if(title.trim().length == 0 || url.trim().length == 0) {
			alert('请填写链接标题或链接地址！');
			return false;
		}
		return true;
	});
});
</script>
</head>

<body>
	<div id="wrapper">
    	<!-- h1 tag stays for the logo, you can use the a tag for linking the index page -->
    	<h1><a href="<spring:url value="/admin.do"/>"><span>Transdmin Light</span></a></h1>
        
        <!-- You can name the links with lowercase, they will be transformed to uppercase by CSS, we prefered to name them with uppercase to have the same effect with disabled stylesheet -->
        <ul id="mainNav">
        	<li><a href="<spring:url value="/admin.do"/>">DASHBOARD</a></li> <!-- Use the "active" class for the active menu item  -->
        	<li><a href="#">ADMINISTRATION</a></li>
        	<li><a href="#">DESIGN</a></li>
        	<li><a href="#">OPTION</a></li>
        	<li class="logout"><a href="#">LOGOUT</a></li>
        </ul>
        <!-- // #end mainNav -->
        
        <div id="containerHolder">
			<div id="container">
        		<div id="sidebar">
                	<ul class="sideNav">
                    	<li><a href="<spring:url value="/admin/category.do"/>">Category</a></li>
                    	<li><a href="<spring:url value="/admin/link.do"/>" class="active">Link</a></li>
                    	<li><a href="<spring:url value="/admin/blog.do"/>">Post</a></li>
                    </ul>
                    <!-- // .sideNav -->
                </div>    
                <!-- // #sidebar -->
                
                <!-- h2 stays for breadcrumbs -->
                <h2><a href="<spring:url value="/admin.do"/>">Dashboard</a> &raquo; <a href="<spring:url value="/admin/link.do"/>" class="active">Link</a></h2>
                
                <div id="main">
                	<form action="" class="jNice">
					<h3>Category List</h3>
                    	<table cellpadding="0" cellspacing="0">
							
                            <c:forEach items="${links }" var="link">
                                <tr>
                                    <td><c:out value="${link.title }"/></td>
                                    <td class="action"><a href="<spring:url value="/admin/link.do?action=edit&key=${link.keyString }"/>" class="edit">Edit</a><a href="<spring:url value="/admin/link.do?action=delete&key=${link.keyString }"/>" class="delete">Delete</a></td>
                                </tr>
                            </c:forEach>
                            
                        </table>
                       <div style="margin: 8;"><strong><p>Pages(<c:out value="${pages }"/>):&nbsp;
                        <c:choose>
                            <c:when test="${pages == 0 }">
                                <c:out value="${pages }"/>
                            </c:when>
                            <c:otherwise>
                                <c:forEach begin="0" end="${pages-1 }" step="1" var="page">
                                    <a href="<spring:url value="/admin/link.do?action=page&page=${page }"/>"><c:out value="${page }"/></a>
                                </c:forEach>
                            </c:otherwise>
                        </c:choose>
                       </p></strong></div>
                    </form>
                    <c:choose>
                        <c:when test="${link == null }">
							<form action="<spring:url value="/admin/link.do?action=add"/>"
								class="jNice" method="post" id="linkForm">
								<h3>Add Link</h3>
								<fieldset>
									<c:if test="${error != null }">
										<div class="error">
											<p>
												<c:out value="${error }" />
											</p>
										</div>
									</c:if>
									<p>
										<label>Link Name:</label><input type="text" class="text-long"
											name="title" id="title" />
									</p>
									<p>
										<label>Link Url:</label><input type="text" class="text-long"
											name="url" id="url" />
									</p>
									<input type="submit" value="Submit" />
								</fieldset>
							</form>
						</c:when>
						<c:otherwise>
							<form action="<spring:url value="/admin/link.do?action=update"/>"
								class="jNice" method="post" id="linkForm">
								<h3>Edit Link</h3>
								<fieldset>
									<c:if test="${error != null }">
										<div class="error">
											<p>
												<c:out value="${error }" />
											</p>
										</div>
									</c:if>
									<p>
										<label>Link Name:</label><input type="text" class="text-long"
											name="title" id="title" value="${link.title }"/>
									</p>
									<p>
										<label>Link Url:</label><input type="text" class="text-long"
											name="url" id="url" value="${link.url }"/>
									</p>
									<input type="hidden" name="key" value="${link.keyString }"/>
									<input type="submit" value="Submit" />
								</fieldset>
							</form>
						</c:otherwise>
                    </c:choose>
                </div>
                <!-- // #main -->
                
                <div class="clear"></div>
            </div>
            <!-- // #container -->
        </div>	
        <!-- // #containerHolder -->
        
        <p id="footer">Feel free to use and customize it. <a href="http://www.perspectived.com">Credit is appreciated.</a></p>
    </div>
    <!-- // #wrapper -->
</body>
</html>
